package com.gyj;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestMap {
	public static void main(String[] args) {
		// 1.模拟查询第一个sql，获取到org，num
		List<OneResult> list1 = new ArrayList<>();
		list1.add(new OneResult("重卡", "11"));
		list1.add(new OneResult("重卡2", "22"));
		list1.add(new OneResult("重卡3", "33"));

		// 2.模拟查询第2个sql，获取到org，num
		List<TwoResult> list2 = new ArrayList<>();
		list2.add(new TwoResult("重卡2", "22"));
		list2.add(new TwoResult("重卡3", "33"));
		list2.add(new TwoResult("重卡4", "44"));

		// 3.模拟查询第3个sql，获取到org，num
		List<ThirdResult> list3 = new ArrayList<>();
		list3.add(new ThirdResult("重卡3", "33"));
		list3.add(new ThirdResult("重卡4", "44"));
		list3.add(new ThirdResult("重卡5", "55"));
		Map<String, String> orgAllMap = new HashMap<String, String>();
		Map<String, String> map = new HashMap<String, String>();
		Map<String, String> map2 = new HashMap<String, String>();
		Map<String, String> map3 = new HashMap<String, String>();
		// 遍历存放map，key=重卡，value=11
		list1.forEach(t -> map.put(t.getOrg(), t.getNum()));
		list2.forEach(t -> map2.put(t.getOrg(), t.getNum()));
		list3.forEach(t -> map3.put(t.getOrg(), t.getNum()));
		// 合并map得到所有的部门，[重卡,重卡2,重卡3,重卡4,重卡5]
		orgAllMap.putAll(map);
		orgAllMap.putAll(map2);
		orgAllMap.putAll(map3);
		System.out.println(orgAllMap.toString());
		// 遍历所有的部门，拼接插入数据serchFish
		List<SerchFish> serchFishList = new ArrayList<>();
		orgAllMap.forEach((k, v) -> {
			SerchFish serchFish = new SerchFish();
			serchFish.setOrg(k);
			serchFish.setNum1(map.get(k) != null ? map.get(k) : "0");
			serchFish.setNum2(map2.get(k) != null ? map2.get(k) : "0");
			serchFish.setNum3(map3.get(k) != null ? map3.get(k) : "0");
			serchFishList.add(serchFish);
		});
		// 批量插入
		System.out.println(serchFishList.toString());
	}

}
